package com.frank.oj.controller.file;

import com.frank.oj.common.result.CommonResult;
import com.frank.oj.service.file.MarkDownFileService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author frank
 * @Date 2024/5/6
 */
@RestController
@RequiresAuthentication
@RequestMapping("/api/file")
public class MarkDownFileController {
    @Resource
    private MarkDownFileService markDownFileService;

    @PostMapping("/upload-md-img")
    public CommonResult<Map<Object, Object>> uploadMDImg(@RequestParam("image") MultipartFile image,
                                                         @RequestParam(value = "gid", required = false) Long gid) {
        return markDownFileService.uploadMDImg(image, gid);
    }


    @GetMapping("/delete-md-img")
    public CommonResult<Void> deleteMDImg(@RequestParam("fileId") Long fileId) {
        return markDownFileService.deleteMDImg(fileId);
    }


    @PostMapping("/upload-md-file")
    public CommonResult<Map<Object, Object>> uploadMd(@RequestParam("file") MultipartFile file,
                                                      @RequestParam(value = "gid", required = false) Long gid) {
        return markDownFileService.uploadMd(file, gid);
    }
}
